package com.stormrage.edu.dao.edu.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.EduProjectDao;
import com.stormrage.entity.edu.EduProject;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
@Repository
public class EduProjectDaoImpl extends MysBaseDao implements EduProjectDao {

	private static final Logger logger = LoggerFactory.getLogger(EduProjectDaoImpl.class);

	@Override
	public Integer create(final EduProject arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Create 】- 开始运行 ");

		final String query = "INSERT INTO edu_project (project, title, detail, cost, target, form, course,"
				+ " linkman, phone, email, certificate, thumb, image) VALUES"
				+ " (:project, :title, :detail, :cost, :target, :form, :course, :linkman, :phone, :email,"
				+ " :certificate, :thumb, :image)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Create 】- 完成运行 ");
		return index;
	}

	@Override
	public void update(final EduProject arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Update 】- 开始运行 ");

		final String query = "UPDATE edu_project SET project = :project, title = :title, detail = :detail, target = :target,"
				+ " form = :form, course = :course, linkman = :linkman, phone = :phone, email = :email,"
				+ " certificate = :certificate, thumb = :thumb, image = :image WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);
		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Update 】- 完成运行 ");

	}

	@Override
	public void delete(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Delete 】- 开始运行 ");

		final String query = "DELETE FROM edu_project WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 Delete 】- 完成运行 ");

	}

	@Override
	public Integer queryCount(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 QueryCount 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM edu_project" + map.get("query");
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);
		logger.debug(" 查询结果的数量为 " + count);

		logger.debug(" 【 Dao 】- 【 EduProjectDao 】- 【 QueryCount 】- 完成运行 ");
		return count;
	}

	@Override
	public EduProject queryById(Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM edu_project WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		EduProject entity = queryObject(query, EduProject.class, map);
		logger.debug(" 查询结果为 " + entity);

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryById 】- 完成运行 ");
		return entity;
	}

	@Override
	public List<EduProject> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM edu_project";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduProject> array = queryList(query, EduProject.class);
		logger.debug(" 查询结果的数量为 " + array.size());

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryList 】- 完成运行 ");
		return array;
	}

	@Override
	public List<EduProject> queryList(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM edu_project" + map.get("query") + " LIMIT :startPage, :size";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduProject> array = queryList(query, EduProject.class, map);
		logger.debug(" 查询结果的数量为 " + array.size());

		logger.debug(" 【 Dao 】- 【 AdmAcctDao 】- 【 QueryList 】- 完成运行 ");
		return array;
	}

}
